﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace VBACodeingTool
{
    public class LoaderModule : LoaderProjectCode
    {
        public LoaderModule(string codeContent,string parentName,ParentType parentType) : base( codeContent,parentName, parentType)
        {
        }

        public override List<ProjectCodeData> ParseCode()
        {
            ParseSubs();
            ParseVariable();
            return projectCodeData;
        }
        public  List<ProjectCodeData> ParseCode(string subContent)
        {
            ParseCode();
            ParseLocalDim(subContent);
            return projectCodeData;
        }
        public void ParseLocalDim(string subContent)
        {
            if (subContent!="" &&subContent!=null)
            {
                Debug.WriteLine(subContent);
                MatchCollection privateVariables = RegexManager.localVariableRegex.Matches(subContent);
                string content = string.Empty;
                foreach (Match variable in privateVariables)
                {
                    if (variable.Success)
                    {
                        content = variable.Groups[1].Value;
                        MatchCollection variables = RegexManager.variableRegex.Matches(content);
                        foreach (Match variable1 in variables)
                        {

                            if (variable1.Success)
                            {
                                content = variable1.Groups[1].Value.Trim();
                                Debug.WriteLine(content);
                                projectCodeData.Add(new ProjectCodeData(false, content, content, 40,
                            ProjectCodeType.Variable, DefaultVariableScopeType, ParentName, ParentType));
                            }
                        }

                    }
                }
            }
        }
    }
}
